<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="cwm" prop="cwm">-->
<!--        <el-input-->
<!--          v-model="queryParams.cwm"-->
<!--          placeholder="请输入cwm"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="tk" prop="tk">-->
<!--        <el-input-->
<!--          v-model="queryParams.tk"-->
<!--          placeholder="请输入tk"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ph" prop="ph">-->
<!--        <el-input-->
<!--          v-model="queryParams.ph"-->
<!--          placeholder="请输入ph"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="xmm" prop="xmm">-->
<!--        <el-input-->
<!--          v-model="queryParams.xmm"-->
<!--          placeholder="请输入xmm"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="lifea" prop="lifea">-->
<!--        <el-input-->
<!--          v-model="queryParams.lifea"-->
<!--          placeholder="请输入lifea"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="wb" prop="wb">-->
<!--        <el-input-->
<!--          v-model="queryParams.wb"-->
<!--          placeholder="请输入wb"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="fa" prop="fa">-->
<!--        <el-input-->
<!--          v-model="queryParams.fa"-->
<!--          placeholder="请输入fa"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="sg" prop="sg">-->
<!--        <el-input-->
<!--          v-model="queryParams.sg"-->
<!--          placeholder="请输入sg"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="coala" prop="coala">-->
<!--        <el-input-->
<!--          v-model="queryParams.coala"-->
<!--          placeholder="请输入coala"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="d" prop="d">-->
<!--        <el-input-->
<!--          v-model="queryParams.d"-->
<!--          placeholder="请输入d"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ri" prop="ri">-->
<!--        <el-input-->
<!--          v-model="queryParams.ri"-->
<!--          placeholder="请输入ri"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:appConcrete:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:appConcrete:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:appConcrete:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
          v-hasPermi="['tool:gen:import']"
        >导入</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:appConcrete:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appConcreteList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="混凝土数据" align="center" prop="id" />-->
      <el-table-column label="Cwm" align="center" prop="cwm" />
      <el-table-column label="T/K" align="center" prop="tk" />
      <el-table-column label="RH" align="center" prop="ph" />
      <el-table-column label="x/mm" align="center" prop="xmm" />
      <el-table-column label="life/a" align="center" prop="lifea" />
      <el-table-column label="w/b" align="center" prop="wb" />
      <el-table-column label="FA/%" align="center" prop="fa" />
      <el-table-column label="SG/%" align="center" prop="sg" />
      <el-table-column label="Coat/a" align="center" prop="coala" />
      <el-table-column label="RD/%" align="center" prop="rd" />
      <el-table-column label="RI/%" align="center" prop="ri" />
      <el-table-column label="Price/Y" align="center" prop="pricey" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:appConcrete:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:appConcrete:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改混凝土数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="cwm" prop="cwm">
          <el-input v-model="form.cwm" placeholder="请输入cwm" />
        </el-form-item>
        <el-form-item label="T/K" prop="tk">
          <el-input v-model="form.tk" placeholder="请输入tk" />
        </el-form-item>
        <el-form-item label="RH" prop="ph">
          <el-input v-model="form.ph" placeholder="请输入ph" />
        </el-form-item>
        <el-form-item label="x/mm" prop="xmm">
          <el-input v-model="form.xmm" placeholder="请输入xmm" />
        </el-form-item>
        <el-form-item label="life/a" prop="lifea">
          <el-input v-model="form.lifea" placeholder="请输入lifea" />
        </el-form-item>
        <el-form-item label="w/b" prop="wb">
          <el-input v-model="form.wb" placeholder="请输入wb" />
        </el-form-item>
        <el-form-item label="FA/%" prop="fa">
          <el-input v-model="form.fa" placeholder="请输入fa" />
        </el-form-item>
        <el-form-item label="SG/%" prop="sg">
          <el-input v-model="form.sg" placeholder="请输入sg" />
        </el-form-item>
        <el-form-item label="Coat/a" prop="coala">
          <el-input v-model="form.coala" placeholder="请输入coala" />
        </el-form-item>
        <el-form-item label="RD/%" prop="rd">
          <el-input v-model="form.d" placeholder="请输入d" />
        </el-form-item>
        <el-form-item label="RI/%" prop="ri">
          <el-input v-model="form.ri" placeholder="请输入ri" />
        </el-form-item>
        <el-form-item label="Price/Y" prop="pricey">
          <el-input v-model="form.pricey" />
        </el-form-item>
<!--        -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <file-upload-import v-if="upload.open" @success="success" :url="url" :fileType="['xlsx']" :showTip="true"></file-upload-import>
      <!--      下载模版。-->
<!--      <el-button type="warning" @click="downloadTemplate" size="mini">下载模版</el-button>-->
    </el-dialog>
  </div>
</template>

<script>
import { listAppConcrete, getAppConcrete, delAppConcrete, addAppConcrete, updateAppConcrete } from "@/api/system/appConcrete";
import {getToken} from "@/utils/auth";

export default {
  name: "AppConcrete",
  data() {
    return {
      // 用户导入参数
      upload: {    // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '导入',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/system/appConcrete/importConcreteData'
      },
      url: '/system/appConcrete/importConcreteData',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 混凝土数据表格数据
      appConcreteList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cwm: null,
        tk: null,
        ph: null,
        xmm: null,
        lifea: null,
        wb: null,
        fa: null,
        sg: null,
        coala: null,
        d: null,
        ri: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询混凝土数据列表 */
    getList() {
      this.loading = true;
      listAppConcrete(this.queryParams).then(response => {
        this.appConcreteList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cwm: null,
        tk: null,
        ph: null,
        xmm: null,
        lifea: null,
        wb: null,
        fa: null,
        sg: null,
        coala: null,
        rd: null,
        ri: null,
        pricey: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加混凝土数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAppConcrete(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改混凝土数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAppConcrete(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppConcrete(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除混凝土数据编号为"' + ids + '"的数据项？').then(function() {
        return delAppConcrete(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/appConcrete/export', {
        ...this.queryParams
      }, `appConcrete_${new Date().getTime()}.xlsx`)
    },
    handleImport(){
      this.upload.open = true;
    },
    success(){
      this.$modal.msgSuccess('导入成功')
      this.upload.open = false
      this.getList();
    },
    downloadTemplate(){
      this.download('system/appQuestion/downQuestionTemplate', {
      }, `appQuestion_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
